import Api from "@/api/api-declare";
import type { APiDriverAuthTypes } from "@/api/api-types/api-driver-auth-types";
import { FLIGHT_CHANNEL_AUDIT_STATUS } from "../enum/pd-enum";
import Store from '@/store';

export function useFlightChanelAuth() {
	//需要审核的接送机渠道信息
	const authChannelList = ref<APiDriverAuthTypes.AuthCheckChannelItem[]>([]);
	//入驻审核状态
	const authStatus = ref(0);

	//获取需要审核的接送机渠道信息
	const getAuthInfo = (): Promise<void> => {
		return new Promise((r) => {
			Api.ApiDriverAuth.checkNeedFlightAuth().then(res => {
				authChannelList.value = res.detail;
				authStatus.value = res.status;
				r();
			});
		});
	};

	//不同审核状态的文案颜色
	const authStatus2Color = (status: FLIGHT_CHANNEL_AUDIT_STATUS) => {
		return {
			[FLIGHT_CHANNEL_AUDIT_STATUS.fail]: '#F86767',
			[FLIGHT_CHANNEL_AUDIT_STATUS.wait]: '#FC894D',
			[FLIGHT_CHANNEL_AUDIT_STATUS.doing]: '#B0B0B0',
			[FLIGHT_CHANNEL_AUDIT_STATUS.success]: '#05BE74',
			[FLIGHT_CHANNEL_AUDIT_STATUS.success_supplement_fail]: '#F86767',
			[FLIGHT_CHANNEL_AUDIT_STATUS.success_supplement_wait]: '#FC894D',
			[FLIGHT_CHANNEL_AUDIT_STATUS.success_supplement_success]: '#05BE74',
		}[status];
	};
	
	//司机车辆信息
	const driverCarInfo = ref<APiDriverAuthTypes.PerfectDriverCarInfo>();
	//获取司机信息（完善车辆信息）
	const getDriverCarInfo = () : Promise<APiDriverAuthTypes.PerfectDriverCarInfo> => {
		return new Promise((r) => {
			Api.ApiDriverAuth.getDriverCarInfo({driver_id:Store.driver().info.id}).then(res => {
				driverCarInfo.value = res.data;
				r(res.data);
			});
		});
	};
	//进行完成车辆信息
	const driverCarInfoUpdate = (data : APiDriverAuthTypes.PerfectDriverConfirm) : Promise<void> => {
		return new Promise((r) => {
			Api.ApiDriverAuth.PerfectDriverUpdate(data).then(() => {
				r();
			});
		});
	};
	return {
		authChannelList,
		authStatus,
		getAuthInfo,
		authStatus2Color,
		getDriverCarInfo,
		driverCarInfo,
		driverCarInfoUpdate
	};
}